from sanic import Sanic
from sanic import html
from sanic import Request,HTTPResponse
from sanic_ext import Extend,Config

from web.goods import router as goods_r
from web.user import router as user_r
from service.scrapy import GoodsSource



app = Sanic(__name__)
cors_config = Config(cors_origins="*",
                     cors_allow_headers="*",
                     cors_allow_methods="*",
                     cors_send_wildcard=True)
Extend(app,config=cors_config)

@app.get("/")
async def home(request: Request):
    return html("<h1>欢迎来到本网站</h1>")

app.ext.add_dependency(GoodsSource,GoodsSource.create)  

app.blueprint(goods_r)
app.blueprint(user_r)
  
if __name__ == "__main__":
    app.run("localhost",8000,dev=True,debug=True,auto_reload=True)